<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>批量翻译</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='bootstrap-4.4.1-dist/css/bootstrap.min.css') }}">
    <script src="{{ url_for('static', filename='jquery-3.7.1.min.js') }}"></script>
    <style>
        h1 {
            text-align: center;
        }

        th, td {
            word-wrap: break-word;
            white-space: normal;
            text-align: center;
            vertical-align: middle;
        }
    </style>
</head>
<body class="container">
<h1 class="my-4">批量翻译</h1>
<form action="/" method="POST" class="mb-4">
    <div class="form-group">
        <label for="mode">模式</label>
        <select name="mode" id="mode" class="form-control">
            <option value="0">百度翻译</option>
            <option value="1">deepseek-v3翻译</option>
        </select>
    </div>
    <div class="form-group">
        <label for="text"></label>
        <textarea name="text" id="text" class="form-control" placeholder="请输入要翻译的文本..." cols="30"
                  rows="4"></textarea>
    </div>
    <button type="submit" class="btn btn-primary">提交</button>
    <button type="reset" class="btn btn-secondary">清除</button>
</form>
<button type="button" class="btn btn-info mb-4" onclick="copyToClip()">复制表格内容</button>

<table id="table" class="table" style="table-layout: fixed;">
    <thead class="thead-dark">
    <tr>
        {% for item in translation.language %}
            <th>{{ item }}</th>
        {% endfor %}
    </tr>
    </thead>
    <tbody>
    {% for row in translation.data %}
        <tr>
            {% for item in row %}
                <td>{{ item }}</td>
            {% endfor %}
        </tr>
    {% endfor %}
    </tbody>
</table>
<script>
    const info = "{{ translation.info|safe }}";
    if (info) {
        console.log("info", info);
        alert(info);
    }

    function copyToClip(contentArray, message) {
        contentArray = `{{ translation.content|safe }}`;
        console.log("contentArray", contentArray);
        const textarea = document.createElement('textarea');
        if (contentArray === '') {
            alert("没有内容可复制");
            return;
        }
        textarea.value = contentArray;
        document.body.appendChild(textarea);
        textarea.select();
        if (document.execCommand('copy')) {
            document.execCommand('copy');
        }
        document.body.removeChild(textarea);
        if (message == null) {
            alert("复制成功");
        } else {
            alert(message);
        }
    }
</script>
</body>
</html>